<template>
  <div>
    <!-- 基本信息 -->
    <div class="addEmissionSourceDictionary-content">
      <div class="addEmissionSourceDictionary-content-title" id="v-step-0">基本信息</div>
      <div class="addEmissionSourceDictionary-content-form">
        <normal-form-plus
          :formModel="formModels.formModel1"
          :config="configs.config1"
          :plus="plus"/>
      </div>
    </div>

    <!-- 活动数据 -->
    <div class="addEmissionSourceDictionary-content">
      <div class="addEmissionSourceDictionary-content-title" id="v-step-1">活动数据</div>
      <div class="addEmissionSourceDictionary-content-form">
        <normal-form-plus
          :formModel="formModels.formModel2"
          :config="configs.config2"
          :plus="plus"/>
      </div>
    </div>

    <!-- 温室气体排放 -->
    <div class="addEmissionSourceDictionary-content">
      <div class="addEmissionSourceDictionary-content-title">温室气体排放</div>
      <div class="addEmissionSourceDictionary-content-form">
        <div class="addEmissionSourceDictionary-content-form-btn">
          <el-button @click="turn" id="v-step-2">选择排放因子</el-button>
        </div>
        <normal-form-plus
          class="addEmissionSourceDictionary-content-form-wen"
          :formModel="formModels.formModel3"
          :config="configs.config3"
          :plus="plus1"/>
      </div>
    </div>

    <!-- 排放因子评价 -->
    <div class="addEmissionSourceDictionary-content">
      <div class="addEmissionSourceDictionary-content-title" id="v-step-3">排放因子评价</div>
      <div class="addEmissionSourceDictionary-content-form">
        <normal-form-plus
          :formModel="formModels.formModel4"
          :config="configs.config4"
          :plus="plus"/>
      </div>
    </div>


    <!-- 操作按钮 -->
    <div class="addEmissionSourceDictionary-btn">
      <el-button type="primary" @click="createEmissionSource()" id="v-step-4">保存</el-button>
    </div>

    <!-- 智能表单-解释说明 -->
    <el-drawer
      title="智能表单助手"
      :visible.sync="drawer"
      :direction="'rtl'">
      <MyChart2/>
    </el-drawer>
    <div class="drawer-btn" @click="drawer = true">></div>

    <!-- 步骤引导 -->
    <v-tour name="myTour" :steps="steps" :options="myOptions"></v-tour>
  </div>
</template>

<script>
import NormalFormPlus from '@/components/NormalFormPlus'
import MyChart2 from '@/components/MyChart2'

export default {
  components: {
    NormalFormPlus,
    MyChart2
  },
  mounted() {
    // 判断是否使用mock数据
    if (this.$MOCK.mock) {
      this.plus1.optionList = [[], [{"value": "三氟化氮（NF3）", "label": "三氟化氮（NF3）"}], [{
        "value": "六氟化硫（SF6）",
        "label": "六氟化硫（SF6）"
      }], [{"value": "全氟化碳（PFCs）", "label": "全氟化碳（PFCs）"}, {
        "value": "PFC-91-18",
        "label": "PFC-91-18",
        "replace": {"gaseId": 39, "name": "PFC-91-18", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 7480}
      }, {
        "value": "PFC-71-18",
        "label": "PFC-71-18",
        "replace": {"gaseId": 38, "name": "PFC-71-18", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 8260}
      }, {
        "value": "PFC-61-16",
        "label": "PFC-61-16",
        "replace": {"gaseId": 37, "name": "PFC-61-16", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 8410}
      }, {
        "value": "PFC-51-14",
        "label": "PFC-51-14",
        "replace": {"gaseId": 36, "name": "PFC-51-14", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 8620}
      }, {
        "value": "PFC-41-12",
        "label": "PFC-41-12",
        "replace": {"gaseId": 35, "name": "PFC-41-12", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 9220}
      }, {
        "value": "PFC-31-10",
        "label": "PFC-31-10",
        "replace": {"gaseId": 34, "name": "PFC-31-10", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 10000}
      }, {
        "value": "PFC-318",
        "label": "PFC-318",
        "replace": {"gaseId": 33, "name": "PFC-318", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 10200}
      }, {
        "value": "PFC-218",
        "label": "PFC-218",
        "replace": {"gaseId": 32, "name": "PFC-218", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 9290}
      }, {
        "value": "PFC-116",
        "label": "PFC-116",
        "replace": {"gaseId": 31, "name": "PFC-116", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 12400}
      }, {
        "value": "PFC-14",
        "label": "PFC-14",
        "replace": {"gaseId": 30, "name": "PFC-14", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 7380}
      }], [{"value": "氢氟碳化物（HFCs）", "label": "氢氟碳化物（HFCs）"}, {
        "value": "HFC-43-10mee",
        "label": "HFC-43-10mee",
        "replace": {"gaseId": 29, "name": "HFC-43-10mee", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 1600}
      }, {
        "value": "HFC-365mfc",
        "label": "HFC-365mfc",
        "replace": {"gaseId": 28, "name": "HFC-365mfc", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 914}
      }, {
        "value": "HFC-329p",
        "label": "HFC-329p",
        "replace": {"gaseId": 27, "name": "HFC-329p", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 2890}
      }, {
        "value": "HFC-272ca",
        "label": "HFC-272ca",
        "replace": {"gaseId": 26, "name": "HFC-272ca", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 599}
      }, {
        "value": "HFC-263fb",
        "label": "HFC-263fb",
        "replace": {"gaseId": 25, "name": "HFC-263fb", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 74.8}
      }, {
        "value": "HFC-245fa",
        "label": "HFC-245fa",
        "replace": {"gaseId": 24, "name": "HFC-245fa", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 962}
      }, {
        "value": "HFC-245eb",
        "label": "HFC-245eb",
        "replace": {"gaseId": 23, "name": "HFC-245eb", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 325}
      }, {
        "value": "HFC-245ea",
        "label": "HFC-245ea",
        "replace": {"gaseId": 22, "name": "HFC-245ea", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 255}
      }, {
        "value": "HFC-245cb",
        "label": "HFC-245cb",
        "replace": {"gaseId": 21, "name": "HFC-245cb", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 4550}
      }, {
        "value": "HFC-245ca",
        "label": "HFC-245ca",
        "replace": {"gaseId": 20, "name": "HFC-245ca", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 787}
      }, {
        "value": "HFC-236fa",
        "label": "HFC-236fa",
        "replace": {"gaseId": 19, "name": "HFC-236fa", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 8690}
      }, {
        "value": "HFC-236ea",
        "label": "HFC-236ea",
        "replace": {"gaseId": 18, "name": "HFC-236ea", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 1500}
      }, {
        "value": "HFC-236cb",
        "label": "HFC-236cb",
        "replace": {"gaseId": 17, "name": "HFC-236cb", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 1350}
      }, {
        "value": "HFC-227ea",
        "label": "HFC-227ea",
        "replace": {"gaseId": 16, "name": "HFC-227ea", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 3600}
      }, {
        "value": "HFC-227ca",
        "label": "HFC-227ca",
        "replace": {"gaseId": 15, "name": "HFC-227ca", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 2980}
      }, {
        "value": "HFC-161",
        "label": "HFC-161",
        "replace": {"gaseId": 14, "name": "HFC-161", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 4.84}
      }, {
        "value": "HFC-152a",
        "label": "HFC-152a",
        "replace": {"gaseId": 13, "name": "HFC-152a", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 164}
      }, {
        "value": "HFC-152",
        "label": "HFC-152",
        "replace": {"gaseId": 12, "name": "HFC-152", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 21.5}
      }, {
        "value": "HFC-143a",
        "label": "HFC-143a",
        "replace": {"gaseId": 11, "name": "HFC-143a", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 5810}
      }, {
        "value": "HFC-143",
        "label": "HFC-143",
        "replace": {"gaseId": 10, "name": "HFC-143", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 364}
      }, {
        "value": "HFC-134a",
        "label": "HFC-134a",
        "replace": {"gaseId": 9, "name": "HFC-134a", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 1530}
      }, {
        "value": "HFC-134",
        "label": "HFC-134",
        "replace": {"gaseId": 8, "name": "HFC-134", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 1260}
      }, {
        "value": "HFC-125",
        "label": "HFC-125",
        "replace": {"gaseId": 7, "name": "HFC-125", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 3740}
      }, {
        "value": "HFC-41",
        "label": "HFC-41",
        "replace": {"gaseId": 6, "name": "HFC-41", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 135}
      }, {
        "value": "HFC-32",
        "label": "HFC-32",
        "replace": {"gaseId": 5, "name": "HFC-32", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 771}
      }, {
        "value": "HFC-23",
        "label": "HFC-23",
        "replace": {"gaseId": 4, "name": "HFC-23", "unitLeft": "", "unitRight": "", "value": "0", "gwp": 14600}
      }], [{"value": "氧化亚氮（N2O）", "label": "氧化亚氮（N2O）"}], [{
        "value": "甲烷（CH4）",
        "label": "甲烷（CH4）"
      }], [{"value": "二氧化碳（CO2）", "label": "二氧化碳（CO2）"}]]
      this.formModels.formModel1 = {
        name: "冷却塔装置", // 排放源名称
        facility: "冷却塔", // 排放设施
        ghgCategory: "范围一", // 	GHG类别
        ghgClassification: "工艺过程", // 	GHG分类
        isoCategory: "直接排放或清除", // 	ISO类别
        isoClassification: "工艺过程" //	ISO分类
      }
      this.formModels.formModel2 = {
        dataCategory: "自动连续量测",//	活动数据类别
        dataRecordMethod: "消耗记录",//		活动数据记录方式
        dataRetentionDept: "行政部",//		活动数据保存部门
        dataScore: "6",//		活动数据评分
        dataUnit: "t", // 活动数据单位
        unitConversion: "2.1", // 单位换算比例
        gwp: "IPCC第六次评估报告", // GWP信息
      }
      this.formModels.formModel3 = {
        "factor": [{
          "gaseId": 1,
          "name": "铁矿石平均",
          "unitLeft": "tCO2-eq",
          "unitRight": "t",
          "value": 1.1,
          "gwp": "-"
        }]
      }
      this.formModels.formModel4 = {
        factorCategory: "量测/质量平衡所得系数", //	排放因子类别
        factorScore: "4.3",    //	排放因子评分
        factorSource: "IPCC", //	排放因子来源
        releaseYear: "2018", //	发布年份
      }
      return
    }

    // 页面初始化前，判断是否有需要获取缓存的数据
    if (this.$route.query.storage) {
      if (JSON.parse(window.sessionStorage.getItem("form"))) {
        this.formModels = JSON.parse(window.sessionStorage.getItem("form"))
        window.sessionStorage.removeItem("form")
      }
    }
    this.id = this.$route.query.id
    if (this.id) {
      this.initData()
    }
    // this.tour()
  },
  data() {
    return {
      myOptions: {
        useKeyboardNavigation: true, // 是否通过键盘的←, → 和 ESC 控制指引
        labels: { // 指引项的按钮文案
          buttonSkip: "跳过指引", // 跳过文案
          buttonPrevious: "上一步", // 上一步文案
          buttonNext: "下一步", // 下一步文案
          buttonStop: "结束" // 结束文案
        },
        highlight: false // 是否高亮显示激活的的target项
      },
      steps: [
        {
          target: "#v-step-0", // 当前项的id或class或data-v-step属性
          content: "1.填写排放源基本信息", // 当前项指引内容
          params: {
            placement: "bottom", // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
        },
        {
          target: "#v-step-1", // 当前项的id或class或data-v-step属性
          content: "2.填写排放源活动数据", // 当前项指引内容
          params: {
            placement: "bottom", // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
        },
        {
          target: "#v-step-2", // 当前项的id或class或data-v-step属性
          content: "3.选择温室气体排放因子填写，因子数据", // 当前项指引内容
          params: {
            placement: "bottom", // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
        },
        {
          target: "#v-step-3", // 当前项的id或class或data-v-step属性
          content: "4.填写因子排放评分", // 当前项指引内容
          params: {
            placement: "bottom", // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
        },
        {
          target: "#v-step-4", // 当前项的id或class或data-v-step属性
          content: "5.保存排放源", // 当前项指引内容
          params: {
            placement: "bottom", // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
        },
      ],
      drawer: false,
      // 标识是否已经添加了气体因子
      addFactor: false,
      categoryList: [],
      plus1: {
        edit: true,
        tableLabel: [
          {
            prop: "name",
            label: "温室气体",
            edit: true,
            type: "select",
            options: [
              {value: '1', label: '0'}
            ]
          },
          {
            prop: "unitLeft",
            label: "因子单位（分子）",
            edit: true
          },
          {
            prop: "unitRight",
            label: "因子单位（分母）",
          },
          {
            prop: "value",
            label: "因子数值",
          },
          {
            prop: "gwp",
            label: "GWP",
            edit: false
          },
        ],
        optionList: [
          [] // 放置一个空的值，用来代替第一个空值
        ]
      },
      plus: {},
      formModels: {
        formModel1: {
          name: "", // 排放源名称
          facility: "", // 排放设施
          ghgCategory: "", // 	GHG类别
          ghgClassification: "", // 	GHG分类
          isoCategory: "", // 	ISO类别
          isoClassification: "" //	ISO分类
        },
        formModel2: {
          dataCategory: "",//	活动数据类别
          dataRecordMethod: "",//		活动数据记录方式
          dataRetentionDept: "",//		活动数据保存部门
          dataScore: "",//		活动数据评分
          dataUnit: "", // 活动数据单位
          unitConversion: "", // 单位换算比例
          gwp: "IPCC第六次评估报告", // GWP信息
        },
        formModel3: {
          factor: []
        },
        formModel4: {
          factorCategory: "", //	排放因子类别
          factorScore: "",    //	排放因子评分
          factorSource: "", //	排放因子来源
          releaseYear: "", //	发布年份
        },
      },
      configs: {
        config1: [
          {
            id: 1,
            items: [
              {
                id: '1',
                edit: true,
                type: 'input',
                span: 8,
                model: 'name',
                name: '排放源名称',
                width: 34,
                props: {
                  placeholder: "排放源名称",
                  width: 200
                }
              },
              {
                id: '3',
                edit: true,
                type: 'input',
                span: 8,
                model: 'facility',
                name: '排放设施',
                width: 40,
                props: {
                  placeholder: "排放设施/活动",
                  width: 200
                }
              }
            ]
          },
          {
            id: 2,
            items: [
              {
                id: '1',
                edit: true,
                type: 'select',
                span: 8,
                model: 'ghgClassification',
                name: 'GHG分类',
                width: 60,
                props: {
                  placeholder: "GHG分类",
                  options: [
                    {value: '范围一', label: '范围一'},
                    {value: '范围二', label: '范围二'},
                    {value: '范围三', label: '范围三'},
                  ]
                }
              },
              {
                id: '2',
                edit: true,
                type: 'select',
                span: 8,
                model: 'ghgCategory',
                name: 'GHG类别',
                width: 70,
                props: {
                  placeholder: "GHG类别",
                  options: [
                    {value: '固定燃烧', label: '固定燃烧'},
                    {value: '移动燃烧', label: '移动燃烧'},
                    {value: '工艺过程', label: '工艺过程'},
                    {value: '无组织排放', label: '无组织排放'},
                    {value: '碳封存', label: '碳封存'},
                    {value: '电力', label: '电力'},
                    {value: '蒸汽', label: '蒸汽'},
                    {value: '压缩空气', label: '压缩空气'},
                    {value: '冷', label: '冷'},
                    {value: '热', label: '热'},
                    {value: '外购商品和服务', label: '外购商品和服务'},
                    {value: '资本商品', label: '资本商品'},
                    {value: '燃料和能源相关活动', label: '燃料和能源相关活动'},
                    {value: '上游运输和配送', label: '上游运输和配送'},
                    {value: '运营中产生的废弃物', label: '运营中产生的废弃物'},
                    {value: '商务旅行', label: '商务旅行'},
                    {value: '雇员通勤', label: '雇员通勤'},
                    {value: '上游租赁资产', label: '上游租赁资产'},
                    {value: '售出产品的运输和配送', label: '售出产品的运输和配送'},
                    {value: '售出产品的加工', label: '售出产品的加工'},
                    {value: '售出产品的使用', label: '售出产品的使用'},
                    {value: '处理寿命终止的售出产品', label: '处理寿命终止的售出产品'},
                    {value: '下游租赁资产', label: '下游租赁资产'},
                    {value: '特许经营权', label: '特许经营权'},
                    {value: '投资', label: '投资'},
                  ]
                }
              },
            ]
          },
          {
            id: 3,
            items: [
              {
                id: '3',
                edit: true,
                type: 'select',
                span: 8,
                model: 'isoClassification',
                name: 'ISO分类',
                width: 60,
                props: {
                  placeholder: "ISO分类",
                  options: [
                    {value: '其他间接排放', label: '其他间接排放'},
                    {value: '供应链下游间接排放', label: '供应链下游间接排放'},
                    {value: '外购产品或服务间接排放', label: '外购产品或服务间接排放'},
                    {value: '运输间接排放', label: '运输间接排放'},
                    {value: '能源间接排放', label: '能源间接排放'},
                    {value: '直接排放或清除', label: '直接排放或清除'},
                  ]
                }
              },
              {
                id: '1',
                edit: true,
                type: 'select',
                span: 8,
                model: 'isoCategory',
                name: 'ISO类别',
                width: 70,
                props: {
                  placeholder: "ISO类别",
                  options: [
                    {value: '其他间接排放', label: '其他间接排放'},
                    {value: '投资', label: '投资'},
                    {value: '产品寿命结束阶段', label: '产品寿命结束阶段'},
                    {value: '下游租赁资产', label: '下游租赁资产'},
                    {value: '产品使用阶段', label: '产品使用阶段'},
                    {value: '其他服务', label: '其他服务'},
                    {value: '资产使用', label: '资产使用'},
                    {value: '固体和液体废物', label: '固体和液体废物'},
                    {value: '资本货物', label: '资本货物'},
                    {value: '采购货物', label: '采购货物'},
                    {value: '商务旅行', label: '商务旅行'},
                    {value: '客户和访客交通运输', label: '客户和访客交通运输'},
                    {value: '员工通勤', label: '员工通勤'},
                    {value: '上游运输和货物分配', label: '上游运输和货物分配'},
                    {value: '热', label: '热'},
                    {value: '冷', label: '冷'},
                    {value: '压缩空气', label: '压缩空气'},
                    {value: '蒸汽', label: '蒸汽'},
                    {value: '电力', label: '电力'},
                    {value: '土地利用、土地利用变化和林业', label: '土地利用、土地利用变化和林业'},
                    {value: '工艺过程', label: '工艺过程'},
                    {value: '逸散排放', label: '逸散排放'},
                    {value: '移动燃烧', label: '移动燃烧'},

                  ]
                }
              }
            ]
          }
        ],
        config2: [
          {
            id: 1,
            items: [
              {
                id: '1',
                edit: true,
                type: 'select',
                span: 8,
                model: 'dataUnit',
                name: '排放数据单位',
                width: 60,
                props: {
                  placeholder: "排放数据单位",
                  options: [
                    {value: 't', label: 't'},
                    {value: 'kg', label: 'kg'}
                  ]
                }
              },
              {
                id: '2',
                edit: true,
                type: 'input',
                span: 8,
                model: 'dataRecordMethod',
                name: '活动数据记录方式',
                width: 60,
                props: {
                  placeholder: "活动数据记录方式",
                  width: 200
                }
              },
              {
                id: '3',
                edit: true,
                type: 'input',
                span: 8,
                model: 'dataRetentionDept',
                name: '活动数据保存部门',
                width: 60,
                props: {
                  placeholder: "活动数据保存部门",
                  width: 200
                }
              }
            ]
          },
          {
            id: 2,
            items: [
              {
                id: '1',
                edit: true,
                type: 'select',
                span: 8,
                model: 'dataCategory',
                name: '活动数据类型',
                width: 60,
                props: {
                  placeholder: "活动数据类型",
                  options: [
                    {value: '自动连续量测', label: '自动连续量测'},
                    {value: '连续量测', label: '连续量测'},
                    {value: '自行推估', label: '自行推估'},
                  ]
                }
              },
              {
                id: '2',
                edit: false,
                type: 'input',
                span: 8,
                model: 'dataScore',
                name: '活动数据评分',
                width: 60,
                props: {
                  placeholder: "活动数据评分",
                  width: 200
                }
              }
            ]
          },
          {
            id: 3,
            items: [
              {
                id: '1',
                edit: false,
                type: 'input',
                span: 8,
                model: 'gwp',
                name: 'GWP信息',
                width: 35,
                props: {
                  placeholder: "GWP信息",
                  width: 200
                }
              },
              {
                id: '2',
                edit: true,
                type: 'input',
                span: 8,
                model: 'unitConversion',
                name: '单位换算比例',
                width: 60,
                props: {
                  placeholder: "单位换算比例",
                  width: 200
                }
              }
            ]
          },
        ],
        config3: [
          {
            id: 1,
            items: [
              {
                id: '1',
                edit: true,
                type: 'table',
                span: 8,
                model: 'factor',
                name: '排放因子',
                width: 100,
                props: {
                  placeholder: "排放因子类别",

                }
              }
            ]
          }
        ],
        config4: [
          {
            id: 1,
            items: [
              {
                id: '1',
                edit: true,
                type: 'select',
                span: 8,
                model: 'factorCategory',
                name: '排放因子类别',
                width: 85,
                props: {
                  placeholder: "排放因子类别",
                  options: [
                    {value: '国际排放系数', label: '国际排放系数'},
                    {value: '国家排放系数', label: '国家排放系数'},
                    {value: '区域排放系数', label: '区域排放系数'},
                    {value: '制造商提供系数', label: '制造商提供系数'},
                    {value: '同制程/设备经验数', label: '同制程/设备经验数'},
                    {value: '量测/质量平衡所得系数', label: '量测/质量平衡所得系数'},
                  ]
                }
              },
              {
                id: '2',
                edit: false,
                type: 'input',
                span: 8,
                model: 'factorScore',
                name: '排放因子评分',
                width: 60,
                props: {
                  placeholder: "排放因子评分",
                  width: 200
                }
              },
              {
                id: '3',
                edit: true,
                type: 'input',
                span: 8,
                model: 'factorSource',
                name: '排放因子来源',
                width: 60,
                props: {
                  placeholder: "排放因子来源",
                  width: 200
                }
              }
            ]
          },
          {
            id: 2,
            items: [
              {
                id: '1',
                edit: true,
                type: 'input',
                span: 8,
                model: 'releaseYear',
                name: '发布年份',
                width: 60,
                props: {
                  placeholder: "发布年份",
                  width: 200
                }
              }
            ]
          },
        ]
      }
    }
  },
  methods: {
    // 初始化表单数据
    initData() {
      // 获取排放源
      this.getEmissionSource()
      // 获取排放源的温室气体列表
      this.getEmissionSourceGasList()
    },
    tour() {
      this.$tours["myTour"].start();
    },
    turn() {
      // 跳转页面前存储一下页面数据
      window.sessionStorage.setItem("form", JSON.stringify(this.formModels))
      this.$router.push("/enterpriseCarbonAccounting/carbonEmissionManage/emissionSourceFactor")
    },
    // 创建排放源
    createEmissionSource() {
      this.$message({
        message: '保存成功',
        type: 'success'
      });
      // this.$router.push("/enterpriseCarbonAccounting/emission/emission-source")
      // return
      this.formModels.formModel2.gwp = "6"
      this.$API.enterprise.createEmissionSource({
        ...this.formModels.formModel1,
        ...this.formModels.formModel2,
        ...this.formModels.formModel4,
        emissionGaseList: this.formModels.formModel3.factor.slice(1),
        co2e: this.formModels.formModel3.factor[0].value,
        unitLeft: this.formModels.formModel3.factor[0].unitLeft,
        unitRight: this.formModels.formModel3.factor[0].unitRight
      }).then(response => {
        if (response.code == "200") {
          this.$router.push("/enterpriseCarbonAccounting/emission/emission-source")
        }
      })
      this.formModels.formModel2.gwp = "IPCC第六次评估报告"
    },
    // 获得排放源
    getEmissionSource() {
      this.$API.enterprise.getEmissionSource({
        id: this.id
      }).then(response => {
        this.formModels.formModel1 = response.data
        this.formModels.formModel2 = response.data
        this.formModels.formModel3.factor = response.data.emissionGaseList
        this.formModels.formModel4 = response.data
      })
    },
    // 获得排放源的温室气体列表
    getEmissionSourceGasList() {
      this.$API.enterprise.getEmissionSourceGasList({
        gwpId: '6'
      }).then(response => {
        // 组织温室气体信息
        var li = response.data
        var find_index;
        for (var i = 0; i < li.length; i++) {
          find_index = -1;
          for (var j = 0; j < this.categoryList.length; j++) {
            if (this.categoryList[j].category == li[i].category) {
              // 找到已有的类
              this.categoryList[j].items.push({
                gaseId: li[i].gaseId,
                name: li[i].name,
                unitLeft: li[i].unitLeft,
                unitRight: li[i].unitRight,
                value: li[i].value,
                gwp: li[i].gwp
              })
              find_index = j;
              break;
            }
          }
          // 没有找到已有的类
          if (find_index == -1) {
            this.categoryList.push({
              category: li[i].category,
              items: [
                {
                  gaseId: li[i].gaseId,
                  name: li[i].name,
                  unitLeft: li[i].unitLeft,
                  unitRight: li[i].unitRight,
                  value: li[i].value,
                  gwp: li[i].gwp
                }
              ]
            })
          }
        }
        // 处理完气体因子后 判断是否要添加到表格中
        this.addGadListToTable()
      })

    },
    // 添加气体因子到列表中
    addGadListToTable() {
      // 如果选择了因子，则提供相关的温室气体数据供使用
      if (this.formModels.formModel3.factor.length > 0) {
        for (var i = 0; i < this.categoryList.length; i++) {
          this.formModels.formModel3.factor.push({
            gaseId: this.categoryList[i].items[0].gaseId,
            name: this.categoryList[i].items[0].name,
            unitLeft: this.categoryList[i].items[0].unitLeft ? this.categoryList[i].items[0].unitLeft : "",
            unitRight: this.categoryList[i].items[0].unitRight ? this.categoryList[i].items[0].unitRight : "",
            value: this.categoryList[i].items[0].value ? this.categoryList[i].items[0].value : "0",
            gwp: this.categoryList[i].items[0].gwp
          })
          // 添加待选项
          this.plus1.optionList.push([])
          this.plus1.optionList[this.plus1.optionList.length - 1].push({
            value: this.categoryList[i].category,
            label: this.categoryList[i].category,
          })
          for (var j = 0; j < this.categoryList[i].items.length; j++) {
            if (this.categoryList[i].items[j].name != this.categoryList[i].category) {
              this.plus1.optionList[this.plus1.optionList.length - 1].push({
                value: this.categoryList[i].items[j].name,
                label: this.categoryList[i].items[j].name,
                replace: {
                  gaseId: this.categoryList[i].items[j].gaseId,
                  name: this.categoryList[i].items[j].name ? this.categoryList[i].items[j].name : "",
                  unitLeft: this.categoryList[i].items[j].unitLeft ? this.categoryList[i].items[j].unitLeft : "",
                  unitRight: this.categoryList[i].items[j].unitRight ? his.categoryList[i].items[j].unitRight : "",
                  value: this.categoryList[i].items[j].value ? this.categoryList[i].items[j].value : "0",
                  gwp: this.categoryList[i].items[j].gwp
                }
              })
            }
          }

        }
        console.log("dealed...")
        console.log(JSON.stringify(this.plus1.optionList))
      }
    }
  },
  watch: {
    // 监听用户是否选择了排放因子
    formModels: {
      handler(newValue, oldValue) {
        // 实现数据级联效果
        // 活动数据类型 - 活动数据评分
        this.formModels.formModel2.dataScore = {
          "自动连续量测": 6,
          "连续量测": 3,
          "自行推估": 1
        }[this.formModels.formModel2.dataCategory]
        this.formModels.formModel4.factorScore = {
          "国际排放系数": 1,
          "国家排放系数": 2,
          "区域排放系数": 3,
          "制造商提供系数": 4,
          "同制程/设备经验数": 5,
          "量测/质量平衡所得系数": 6
        }[this.formModels.formModel4.factorCategory]
        if (this.formModels.formModel2 && this.formModels.formModel2.dataCategory && this.formModels.formModel2.dataScore) {

        }
        if (this.formModels.formModel4 && this.formModels.formModel4.factorCategory && this.formModels.formModel2.factorScore) {

        }

      },
      deep: true,
      // immediate:true
    }
  }
}
</script>

<style lang="less" scoped>
.drawer-btn {
  position: fixed;
  top: 400px;
  right: 20px;
}

.addEmissionSourceDictionary-content {

  padding: 10px;
  margin: 10px 0px;

  .addEmissionSourceDictionary-content-title {
    font-size: 18px;
    font-weight: 800;
    width: 200px;
  }

  .addEmissionSourceDictionary-content-form {
    margin: 20px 0px;

    .addEmissionSourceDictionary-content-form-wen {
      width: 230vw;
    }

    .addEmissionSourceDictionary-content-form-btn {

    }
  }
}

.v-step {

}

.v-tour__target--highlighted {
  box-shadow: 0 0 0 99999px rgba(0, 0, 0, .4);
}
</style>
